/**
 * This creates the UI for the user to handle events;
 */
package View;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

/**
 * This class holds and displays any random events that occur
 * @author Whitney
 * @version 1.0
 */
public class EventWindow extends JPanel{
	
	/**
	 * The Lables for Event Window
	 */
	private final JLabel eventLbl, imageLbl;
	
	/**
	 * The Button for Event Window
	 */
	private final JButton acceptBtn;
	
	/**
	 * The int returned when the button is pressed
	 */
	private int buttonPressed = -1;
	
	/**
	 * The main method displays an event image, event string, and an "acceptance"
	 * button. You can't not accept an event. You have to accept what life hands you.
	 * Our game deals with life's hard truths.
	 * @param eventNum the int value of the event
	 * @param eventString the string that comes along with the event
	 */
	public EventWindow(int eventNum, String eventString){
		System.out.println("Num: " + eventNum);
		setBackground(Color.LIGHT_GRAY);
		setLayout(null);
		
		final Dimension prefSize = new Dimension(400, 400);
		setPreferredSize(prefSize);
		
		final ImageIcon eventImg = new ImageIcon 
				("images/EventImages/event" + eventNum + ".png");
		final ButtonListener listen = new ButtonListener();
		
		eventLbl = new JLabel(eventString);
		eventLbl.setBounds(5, 330, 450, 25);
		eventLbl.setFont(new Font("Krungthep", Font.PLAIN, 10));
		acceptBtn = new JButton("Alright");
		acceptBtn.setBounds(150, 395, 90, 25);
		acceptBtn.addActionListener(listen);
		imageLbl = new JLabel("", eventImg, SwingConstants.CENTER);
		imageLbl.setBounds(0, 0, 400, 300);
	
		add(imageLbl);
		add(eventLbl);
		add(acceptBtn);
	}

	/**
	 * This class handles the acceptance button on the Event Window
	 * @author Whitney
	 *
	 */
	private class ButtonListener implements ActionListener{
		/**
		 * Checks for the button having been pressed
		 * @param event Event that occured
		 */
		public void actionPerformed (ActionEvent event){
			if(event.getSource().equals(acceptBtn) ){
				buttonPressed = 1;
			}
		}

		/**
		 * The toString for the ButtonListener
		 * @return Returns a space because the button listener doesn't need a toString. */
		public String toString(){
			return "";
			
		}
	}
	
	/**
	 * This returns the int value of the button pressed
	 * @return the int of the button pressed. -1 if none, 1 if accept
	 */
	public int getButtonPressed(){
		return buttonPressed;
	}
}
